<?php

namespace app\middleware;

use app\manager\RedisInstance;
use app\model\RegisterModel;
use app\model\UserModel;
use app\util\UserContext;
use think\Exception;
use think\facade\Cache;
use think\facade\Log;
use think\facade\Request;
use think\facade\Session;
use think\facade\View;
use think\response\Json;



/**todo
 * 统一返回格式分装
 * 新增拦截器完成统一异常捕获
 * */
class CheckToken2
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        session_start();
        $urls = [
            '/login/login',
            'register',
            '/user/login'
        ];
        if (in_array(Request::url(),$urls)){
            return $next($request);
        } else {
            if (empty($_SESSION['uid'])){
                return redirect('/user/login');
            } else{
                return $next($request);
            }

        }
    }
}
